<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var str = 'aa.bb.cc',
      obj = {
        aa: {
          bb: {
            cc: 'okokok'
          }
        }
      }

    // var res = str.split('.').reduce((data, curr) => {
    //   return data[curr]
    // }, obj)

    // console.log('res', res);

    function getObjDataFromStr (str, obj,final) {
      var arr = str.split('.')
      return arr.reduce((data, curr, ind) => {
          if (final && ind === arr.length - 1) return data[curr] = final 
          return data[curr]
      }, obj) 
    }

    console.log(getObjDataFromStr(str,obj,'ccc'));
    console.log(obj);
  </script>
</body>

</html>